# Use Ubuntu as the base image
FROM ubuntu:22.04

# Update apt sources to use Tencent Cloud mirror
# RUN sed -i 's|http://archive.ubuntu.com|https://mirrors.cloud.tencent.com|g' /etc/apt/sources.list

# Install basic tools and packages, including CA certificates and vim
RUN apt-get update && \
    apt-get install -y zsh curl wget git zip ca-certificates vim && \
    rm -rf /var/lib/apt/lists/*

# Install Golang
RUN wget https://golang.google.cn/dl/go1.23.3.linux-amd64.tar.gz && \
    tar -C /usr/local -xzf go1.23.3.linux-amd64.tar.gz && \
    rm go1.23.3.linux-amd64.tar.gz

# Set up Go environment
ENV PATH="/usr/local/go/bin:${PATH}"

# Set Go proxy
ENV GOPROXY=https://goproxy.cn,https://goproxy.io,direct 

# Set zsh as the default shell
RUN chsh -s $(which zsh)

# Create a new user 'worker'
RUN useradd -ms /bin/zsh worker

# Switch to 'worker' user
USER worker

# Set working directory
WORKDIR /home/worker

# Copy Oh My Zsh installation script into the container
COPY scripts/oh-my-zsh.sh /tmp/oh-my-zsh.sh

# Install Oh My Zsh for the worker user
RUN sh /tmp/oh-my-zsh.sh && \
    git clone https://github.com/zsh-users/zsh-autosuggestions /home/worker/.oh-my-zsh/custom/plugins/zsh-autosuggestions && \
    git clone https://github.com/zsh-users/zsh-syntax-highlighting /home/worker/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting

RUN go install github.com/go-task/task/v3/cmd/task@latest


# Copy all configuration files into the worker's home directory and set ownership to worker
COPY --chown=worker:worker config/. /home/worker/

# Define default command
CMD ["zsh"]
